/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game.platformer.levels;

import game.platformer.Player;
import game.platformer.platformer;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.IEntity;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

public class levelHazards extends Sprite{
	private int nextLevel;
	private int xEntryPoint, yEntryPoint;
	private static TextureRegion fireHazard = null;

	/**
	 * This function initializes the exit to use this texture region for its sprite
	 * It is a good idea to create the TextureRegion in platformer.loadResources, then
	 * call this static function using the created texture region as the paramiter.
	 *
	 * @param tr
	 */
       
        public static void initializeFireHazardSprite(TextureRegion fireHazardTR){
                fireHazard = fireHazardTR;
        }

	/**
	 * sets up the exit point of the level. when the player collides with the exit, the next level is loaded
	 *
	 * @param exitPosX  the position of the exit
	 * @param exitPosY  the position of the exit
	 * @param entrancePosX where the player is placed upon entry into the level
	 * @param entrancePosY where the player is placed upon entry into the level
	 * @param nextLevel the next level to be loaded
	 */
	protected levelHazards(int exitPosX, int exitPosY, final int entrancePosX, final int entrancePosY, final int nextLevel){
		//set up the square
		super(exitPosX, exitPosY, fireHazard);
                //save paramiters
		this.nextLevel = nextLevel;
		xEntryPoint = entrancePosX;
		yEntryPoint = entrancePosY;
		//add an update handler to check for collision with the player
		registerUpdateHandler(new IUpdateHandler() {
			public void onUpdate(float pSecondsElapsed){
				if(collidesWith(Player.getPlayer().getSprite())){
                                    Player.getPlayer().place(entrancePosX, entrancePosY);// move to next level
                                    Player.getPlayer().hurt(1);
                                }
			}
			public void reset(){
				//do nothing
			}
		});
	}
        
        
        	
	/**
	 * force the next level to load
	 */
	
	public void place(){
		platformer.getScreenManager().getMapScreen().attachChild(this);
	}
}
